package com.atguigu.bigdata.spark.core.rdd.builder;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.VoidFunction;
import org.apache.spark.rdd.RDD;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Spark01_RDD_Memory_JAVA {
    public static void main(String[] args) {
        // TODO 准备环境
        SparkConf conf = new SparkConf().setMaster("local[*]").setAppName("sparkCore");
        JavaSparkContext sc = new JavaSparkContext(conf);
        // TODO 创建RDD
        // 从内存中创建RDD，将内存中集合的数据作为处理的数据源  使用parallelize
        List<Integer> seq = Arrays.asList(1,2,3,4,5);
        JavaRDD<Integer> rdd = sc.parallelize(seq);

        //打印
        rdd.foreach(new VoidFunction<Integer>() {
            @Override
            public void call(Integer integer) throws Exception {
                System.out.println(integer);
            }
        });

        sc.stop();
    }

}
